#include"sort.h"

int main()
{
	vector<int> a;
	cout << "请输入20个已基本有序的数据：";
	for (int i = 0; i < 20; ++i)
	{
		int e;
		cin >> e;
		a.push_back(e);
	}
	vector<int> b;
	cout << "请输入20个逆序的数据：";
	for (int i = 0; i < 20; ++i)
	{
		int e;
		cin >> e;
		b.push_back(e);
	}
	vector<int> c;
	FILE* fp;
	fopen_s(&fp,"a.txt", "w");   //这里由于我采用vs，故使用fopen_s
	srand((size_t)time(NULL));
	for (int i = 0; i < 20000; ++i)  //随机生成20000个数据
	{
		int e = rand();
		c.push_back(e);
		fprintf(fp, "%d ", e);
	}
	fclose(fp);
	fp = NULL;
	cout << "对于测试点a（20个已基本有序的数据）请选择您想要进行的排序：0-插入排序 1-冒泡排序 2-选择排序 3-快速排序 4-归并排序";
	int choice1;
	cin >> choice1;
	switch (choice1)
	{
	case 0:
		InsertSort(a);
		break;
	case 1:
		BubbleSort(a);
		break;
	case 2:
		SelectSort(a);
		break;
	case 3:
		QuickSort(a, 0, a.size() - 1);
		break;
	case 4:
		MergeSort(a, 0, a.size() - 1);
		break;
	default:
		cout << "请输入正确的选项！" << endl;
	};

	cout << "对于测试点b（20个逆序的数据）请选择您想要进行的排序：0-插入排序 1-冒泡排序 2-选择排序 3-快速排序 4-归并排序";
	int choice2;
	cin >> choice2;
	switch (choice2)
	{
	case 0:
		InsertSort(b);
		break;
	case 1:
		BubbleSort(b);
		break;
	case 2:
		SelectSort(b);
		break;
	case 3:
		QuickSort(b, 0, b.size() - 1);
		break;
	case 4:
		MergeSort(b, 0, b.size() - 1);
		break;
	default:
		cout << "请输入正确的选项！" << endl;
	};

	cout << "对于测试点c（20000个随机的数据）请选择您想要进行的排序：0-插入排序 1-冒泡排序 2-选择排序 3-快速排序 4-归并排序";
	int choice3;
	cin >> choice3;
	switch (choice3)
	{
	case 0:
		InsertSort(c);
		break;
	case 1:
		BubbleSort(c);
		break;
	case 2:
		SelectSort(c);
		break;
	case 3:
		QuickSort(c, 0, c.size() - 1);
		break;
	case 4:
		MergeSort(c, 0, c.size() - 1);
		break;
	default:
		cout << "请输入正确的选项！" << endl;
	};

	//最后输出测试点a、b，将测试点c的数据保存至文件a.txt中
	//测试点a
	cout << "20个基本有序序列数组a[]排序后序列：";
	for (int i = 0; i < a.size(); ++i) cout << a[i] << " ";
	cout << endl;
	//测试点b
	cout << "20个逆序序列数组b[]排序后序列：";
	for (int i = 0; i < b.size(); ++i) cout << b[i] << " ";
	cout << endl;
	//测试点c
	cout << "20000个随机整数数组c[]排序后序列请在项目文件夹中查看a.txt文件" << endl;
	fopen_s(&fp,"a.txt", "a");   //这里由于我采用vs，故使用fopen_s
	fprintf(fp, "\n\n\n\n");
	for (int i = 0; i < c.size(); ++i)
	{
		fprintf(fp, "%d ", c[i]);
	}
	fprintf(fp, "\n");
	fclose(fp);
	fp = NULL;
	return 0;
}